/*
 * Copyright (c) 1997 - 2012 Rakuten, Inc. All Rights Reserved.
 * $Id$
 * Created on 2012/05/24
 */
package com.rakuten.api.mule.model;

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonPropertyOrder;

/**
 *
 * @author hayatsu
 */
@JsonPropertyOrder({
	"itemId",
	"merchantId",
	"baseSku",
	"name",
	"tagline",
	"descriptionHtml",
	"brand",
	"isAdultOnly",
	"isGiftWrappable",
	"isFreeShipping",
	"isInventoryHidden",
	"searchableStartTime",
	"shippingStartTime",
	"duration",
	"inactiveTime",
	"rakutenCategoryId",
	"videoUrl",
	"images",
	"variantLabels",
	"variants",
	"shopInfo",
	"lastModified",
})
public class Item implements Durability{
	private String itemId;
	private String merchantId;
	private String baseSku;
	private MultiLang name;
	private MultiLang tagline;
	private MultiLang descriptionHtml;
	private String brand;
	@JsonProperty("isAdultOnly")
	private Boolean adultOnly;
	@JsonProperty("isGiftWrappable")
	private Boolean giftWrappable;
	@JsonProperty("isFreeShipping")
	private Boolean freeShipping;
	@JsonProperty("isInventoryHidden")
	private Boolean inventoryHidden;
	private Date searchableStartTime;
	private Date shippingStartTime;
	private ItemDuration duration;
	private Date inactiveTime;
	private Integer rakutenCategoryId;

	private String videoUrl;
	private List<ItemImage> images;
	private List<MultiLang> variantLabels;
	private List<ItemVariant> variants;

	//key=shopId
	@JsonProperty("shopInfo")
	private Map<String, ShopInfo> shopInfoMap;

	private Date lastModified;

	public Integer getRakutenCategoryId(){
		return rakutenCategoryId;
	}

	public void setRakutenCategoryId(Integer rakutenCategoryId){
		this.rakutenCategoryId=rakutenCategoryId;
	}

	public List<ItemImage> getImages(){
		return images;
	}

	public void setImages(List<ItemImage> images){
		this.images=images;
	}

	public String getVideoUrl() {
		return videoUrl;
	}

	public void setVideoUrl(String videoUrl) {
		this.videoUrl = videoUrl;
	}

	@Override
	public ItemDuration getDuration(){
		return duration;
	}

	@Override
	public void setDuration(ItemDuration duration){
		this.duration=duration;
	}
	@Override
	public boolean isLive(long currentTimeMillis){
		return duration!=null&&duration.isLive(currentTimeMillis);
	}

	public Map<String, ShopInfo> getShopInfoMap(){
		return shopInfoMap;
	}

	public void setShopInfoMap(Map<String, ShopInfo> shopInfoMap){
		this.shopInfoMap=shopInfoMap;
	}

	public boolean isShopVisible(String shopId, long currentTimeMillis){
		if(shopInfoMap==null) return false;
		ShopInfo info=shopInfoMap.get(shopId);
		if(info==null) return false;
		ItemDuration dur=info.getDuration();
		return dur!=null&&dur.isLive(currentTimeMillis);
	}

	public ShopInfo getShopInfo(String shopId){
		return shopInfoMap==null?null:shopInfoMap.get(shopId);
	}

	public ShopInfo getOrCreateShopInfo(String shopId){
		if(shopInfoMap==null) shopInfoMap=new java.util.HashMap<>();
		ShopInfo ret=shopInfoMap.get(shopId);
		if(ret==null) shopInfoMap.put(shopId, ret=new ShopInfo());
		return ret;
	}

	public Date getSearchableStartTime(){
		return searchableStartTime;
	}

	public void setSearchableStartTime(Date searchableStartTime){
		this.searchableStartTime=searchableStartTime;
	}

	public Date getShippingStartTime(){
		return shippingStartTime;
	}

	public void setShippingStartTime(Date shippingStartTime){
		this.shippingStartTime=shippingStartTime;
	}

	public MultiLang getDescriptionHtml(){
		return descriptionHtml;
	}

	public void setDescriptionHtml(MultiLang descriptionHtml){
		this.descriptionHtml=descriptionHtml;
	}

	public String getBrand(){
		return brand;
	}

	public void setBrand(String brand){
		this.brand=brand;
	}

	public Date getInactiveTime(){
		return inactiveTime;
	}

	public void setInactiveTime(Date inactiveTime){
		this.inactiveTime=inactiveTime;
	}

	public Boolean isAdultOnly(){
		return adultOnly;
	}
	/**
	 * Returns the unwrapped primitive type if the attribute is set, otherwise returns <code>false</code> by default.
	 */
	public boolean unwrapAdultOnly(){
		return adultOnly==null?false:adultOnly.booleanValue();
	}

	public void setAdultOnly(Boolean adultOnly){
		this.adultOnly=adultOnly;
	}

	public Boolean isFreeShipping(){
		return freeShipping;
	}
	/**
	 * Returns the unwrapped primitive type if the attribute is set, otherwise returns <code>false</code> by default.
	 */
	public Boolean unwrapFreeShipping(){
		return freeShipping==null?false:freeShipping.booleanValue();
	}

	public void setFreeShipping(Boolean freeShipping){
		this.freeShipping=freeShipping;
	}

	public Boolean isGiftWrappable(){
		return giftWrappable;
	}
	/**
	 * Returns the unwrapped primitive type if the attribute is set, otherwise returns <code>false</code> by default.
	 */
	public boolean unwrapGiftWrappable(){
		return giftWrappable==null?false:giftWrappable.booleanValue();
	}

	public void setGiftWrappable(Boolean giftWrappable){
		this.giftWrappable=giftWrappable;
	}

	public Boolean isInventoryHidden(){
		return inventoryHidden;
	}
	/**
	 * Returns the unwrapped primitive type if the attribute is set, otherwise returns <code>false</code> by default.
	 */
	public boolean unwrapInventoryHidden(){
		return inventoryHidden==null?false:inventoryHidden.booleanValue();
	}

	public void setInventoryHidden(Boolean inventoryHidden){
		this.inventoryHidden=inventoryHidden;
	}

	public String getItemId(){
		return itemId;
	}

	public void setItemId(String itemId){
		this.itemId=itemId;
	}

	public String getMerchantId(){
		return merchantId;
	}

	public void setMerchantId(String merchantId){
		this.merchantId=merchantId;
	}

	public MultiLang getName(){
		return name;
	}

	public void setName(MultiLang name){
		this.name=name;
	}

	public String getBaseSku(){
		return baseSku;
	}

	public void setBaseSku(String baseSku){
		this.baseSku=baseSku;
	}

	public MultiLang getTagline(){
		return tagline;
	}

	public void setTagline(MultiLang tagline){
		this.tagline=tagline;
	}

	public List<MultiLang> getVariantLabels(){
		return variantLabels;
	}

	public void setVariantLabels(List<MultiLang> variantLabels){
		this.variantLabels=variantLabels;
	}

	public List<ItemVariant> getVariants(){
		return variants;
	}

	public void setVariants(List<ItemVariant> variants){
		this.variants=variants;
	}

	public Date getLastModified(){
		return lastModified;
	}

	public void setLastModified(Date lastModified){
		this.lastModified=lastModified;
	}

	
	
	@JsonPropertyOrder({
		"duration",
		"categoryIds",
		"shopShippingMethodIds",
		"shopPaymentMethodIds"
	})
	public static class ShopInfo{
		private ItemDuration duration;
		private List<String> categoryIds;
		private List<String> shopShippingMethodIds;
		private List<String> shopPaymentMethodIds;
		
		public ItemDuration getDuration(){
			return duration;
		}

		public void setDuration(ItemDuration duration){
			this.duration=duration;
		}

		public List<String> getCategoryIds(){
			return categoryIds;
		}

		public void setCategoryIds(List<String> categoryIds){
			this.categoryIds=categoryIds;
		}

		public List<String> getShopShippingMethodIds() {
			return shopShippingMethodIds;
		}

		public void setShopShippingMethodIds(List<String> shopShippingMethodIds) {
			this.shopShippingMethodIds = shopShippingMethodIds;
		}

		public List<String> getShopPaymentMethodIds() {
			return shopPaymentMethodIds;
		}

		public void setShopPaymentMethodIds(List<String> shopPaymentMethodIds) {
			this.shopPaymentMethodIds = shopPaymentMethodIds;
		}
	}
}
